package com.szjz.rabbitmq.client.onetoone;

import com.rabbitmq.client.*;
import com.szjz.rabbitmq.client.util.RabbitMQUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;


/**
 * @author 史博
 * @desc mq消费者
 * @date 2020/8/22 3:21 下午 周六
 */
@Slf4j
public class Consumer {


    @SneakyThrows
    public static void main(String[] args) {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("slc.pigform.imy", true, false, false, null);
        // 消费消息
        channel.basicConsume("slc.pigform.imy", true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag,
                                       Envelope envelope,
                                       AMQP.BasicProperties properties,
                                       byte[] body) {
                log.info("msg: {}", new String(body));
            }
        });

    }
}

